package asteroids.model;

import be.kuleuven.cs.som.annotate.*;
import asteroids.Util;
import asteroids.Vector;

/**
 * @author Thijs Dieltjens - Wim Konings 
 * |2BCwaElt
 * |https://asteroids-ogp.googlecode.com/svn/trunk/
 * @version 2.0
 *
 *This class represents a collision that can happen at a certain time on a certain position with one or two spaceObjects.
 *
 * @invar Given position of collision can not be null.
 * 		|this.getPosition() !=null
 * @invar The first spaceObject is never null.
 * 		|this.getSpaceObject() !=null
 * @invar The time is always bigger than zero.
 * 		|this.getTime()>0
 * @invar The two spaceObjects cannot be equal.
 * 		|this.getSpaceObject!=this.getSpaceObject
 */
public class Collision {


	/**
	 * This creates a collision object.
	 * @param time
	 * 			The time on which the collision will take place.
	 * @param position
	 * 			The collision position
	 * @param spaceObject
	 * 			The first spaceObject that will collide
	 * @param spaceObject2
	 * 			 The second spaceObject that will collide
	 * @throws IllegalArgumentException
	 * 			One of the given arguments do not correspond to the class invariant.
	 * 			|((position==null || spaceObject==null || Util.fuzzyLessThanOrEqualTo(time, 0)) || (spaceObject==spaceObject2))
	 */
	@Raw
	public Collision(double time, Vector position, SpaceObject spaceObject, SpaceObject spaceObject2) throws IllegalArgumentException{
		if(position==null || spaceObject==null || Util.fuzzyLessThan(time, 0) || spaceObject==spaceObject2){
			throw new IllegalArgumentException();
		}
		else{
			this.position=position;
			this.time=time;
			this.firstSpaceObject=spaceObject;
		}

		this.secondSpaceObject=spaceObject2;
	}

	/**
	 * Returns the time until there is a collision.
	 */
	@Basic @Immutable
	public double getTime() {
		return time;
	}

	private final double time;

	/**
	 * Returns the position of this collision.
	 */
	@Basic @Immutable
	public Vector getPosition() {
		return position;
	}

	private final Vector position;

	/**
	 * Returns the first space object in this collision.
	 */
	@Basic @Immutable
	public SpaceObject getFirstSpaceObject() {
		return firstSpaceObject;
	}

	private final SpaceObject firstSpaceObject;
	
	/**
	 * Returns the second space object in this collision.
	 */
	@Basic @Immutable
	public SpaceObject getSecondSpaceObject() {
		return secondSpaceObject;
	}

	private final SpaceObject secondSpaceObject;


}
